<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>五星好评</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            line-height: 35px;
        }

        li {
            width: 50px;
            height: 100px;
            background: url(./img/star_fill.png) no-repeat;
            float: left;
            list-style: none;
            margin: 5px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div>
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <span></span>
    </div>
</body>
<script src="../js/jQuery.js"></script>
<script>
    var timer = null;
    var oldTndex = -1;
    $("li").mouseover(function () {
        clearTimeout(timer)
        var index = $(this).index();
        $("li").slice(0, index + 1).css("background-image", "url(./img/star_fill.png)")
        $("li").slice(index + 1).css("background-image", "url(./img/star.png)")
    }).mouseout(function () {
        timer = setTimeout(() => {
            $("li").slice(0, oldIndex + 1).css("background-image", "url(./img/star_fill.png)")
            $("li").slice(oldIndex + 1).css("background-image", "url(./img/star.png)")
        },200);
    })

    $("li").click(function () {
        oldIndex = $(this).index()
    })
</script>

</html>